package top.yangyitao.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.yangyitao.dao.RegisterCodeDao;
import top.yangyitao.model.RegisterCode;
import top.yangyitao.service.RegisterCodeService;

@Transactional
@Service("registerCodeService")
public class RegisterCodeServiceImpl implements RegisterCodeService {

	@Resource
	private RegisterCodeDao registerCodeDao;
	@Override
	public boolean checkRegisterCode(String userName,String registerCode) {
		RegisterCode registerCode0 = registerCodeDao.findRegisterCodeByUserName(userName);
		if(registerCode0==null)
			return false;
		else{
				long registerTime = Long.parseLong(registerCode0.getRegisterTime());
				if((new Date().getTime()-registerTime<1000*60*60*3)&&(registerCode0.getRegisterCode().equals(registerCode)))
					return true;
				else
					return false;
		}
	}
	
	@Override
	public void deleteRegisterCodeByUserName(String userName) {
		registerCodeDao.deleteRegisterCodeByUserName(userName);
	}
	
	@Override
	public void updateRegisterCodeByUserName(String userName) {
		registerCodeDao.updateRegisterCodeByUserName(userName);
	}
}
